package com.artqiyi.dollmachine.views.adapter;

import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.widget.TextView;

import com.artqiyi.dollmachine.R;
import com.artqiyi.dollmachine.common.constant.Constant;
import com.artqiyi.dollmachine.model.entity.CoinRecordBean;
import com.artqiyi.dollmachine.utils.CompatUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2017/10/30 0030.
 */

public class MineDollCoinAdapter extends BaseQuickAdapter<CoinRecordBean, BaseViewHolder>{

    public MineDollCoinAdapter(@Nullable List<CoinRecordBean> data) {
        super(R.layout.item_mine_doll_coin, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CoinRecordBean item) {
        helper.setText(R.id.tvName, setItemName(item.getRecordable_type()));
        helper.setText(R.id.tvTime, item.getCreated_at());
        setCoinText((TextView)helper.getView(R.id.tvCoin), item.getCoin());
    }

    private String setItemName(String recordable_type) {
        if (TextUtils.equals(recordable_type, Constant.RECORDABLE_TYPE_PAYMENT)) {
            return "充值";
        } else if (TextUtils.equals(recordable_type, Constant.RECORDABLE_TYPE_GAME_RECORD)){
            return "游戏消费";
        } else if (TextUtils.equals(recordable_type, Constant.RECORDABLE_TYPE_PAYMENT_AWARD)){
            return "充值赠送";
        } else if (TextUtils.equals(recordable_type, Constant.RECORDABLE_TYPE_REGISTER)){
            return "新用户注册";
        } else if (TextUtils.equals(recordable_type, Constant.RECORDABLE_TYPE_SYSTEM)){
            return "系统赠送";
        } else {
            return "未知";
        }
    }

    private void setCoinText(TextView view, int coin) {
        if (coin > 0) {
            view.setText("+" + coin);
            view.setTextColor(CompatUtil.getColor(mContext, R.color.c6cdd73));
        } else {
            view.setText(String.valueOf(coin));
            view.setTextColor(CompatUtil.getColor(mContext, R.color.cffb52b));
        }
    }
}
